<?php

declare(strict_types=1);

namespace App\Request\Admin;

use App\Constants\Model\AdminMenu;
use Hyperf\Validation\Request\FormRequest;
use Hyperf\Validation\Rule;

class AdminMenuRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'pid' => 'nullable',
            'name' => 'required',
            'type' => 'required',
            'path' => Rule::requiredIf(function(){
                return $this->type == AdminMenu::TYPE_PATH;
            }),
            'api' =>  Rule::requiredIf(function(){
                return $this->type == AdminMenu::TYPE_API;
            })
        ];
    }
}
